using System;
using CustomerContactSystem.Core.Infrastructure.Domain;

namespace CustomerContactSystem.Core.Model {
    public class EnquiryReferral : Entity {
        public virtual Enquiry Enquiry { get; set; }
        public virtual DateTime DateReferred { get; set; }
        public virtual User ReferredTo { get; set; }
        public virtual Department ReferredToDepartment { get; set; }
        public virtual UserGroup ReferredToGroup { get; set; }

        protected override void Validate() {
            if (Enquiry == null) {
                AddBrokenRule(new BusinessRule("Enquiry", "Enquiry is required!"));
            }

            if (DateReferred == DateTime.MinValue) {
                AddBrokenRule(new BusinessRule("DateReferred", "Date referred is required!"));
            }

            if (ReferredTo == null || ReferredTo.Id == 0) {
                AddBrokenRule(new BusinessRule("ReferredTo", "Referred to is required!"));
            }

            if (ReferredToDepartment == null || ReferredToDepartment.Id == 0) {
                AddBrokenRule(new BusinessRule("ReferredToDepartment", "Department is required!"));
            }

            if (ReferredToGroup == null || ReferredToGroup.Id == 0) {
                AddBrokenRule(new BusinessRule("ReferredToGroup", "Group is required!"));
            }
        }
    }
}